package com.darco.darcoapp;

import static DARCOShared.utils.Constants.*;

import java.io.ByteArrayInputStream;

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class AccountInfo_Activity extends Activity {
	private Bundle extra=null;
	private ContentValues account=null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_accountinfo_);
		
		extra=getIntent().getExtras();
		
		
		if(extra!=null){
			account=((ContentValues) extra.get("account"));

			//reperimento delle informazioni dal contentValues
			byte[] image_avatar = account.getAsByteArray(ACCOUNT_AVATAR);
			String account_username = account.getAsString(ACCOUNT_USERNAME);
			String account_ID = account.getAsString(ACCOUNT_ID);
			String account_creationDate = account.getAsString(ACCOUNT_CREATION);
			String account_email = account.getAsString(ACCOUNT_EMAIL);
			String account_name = account.getAsString(ACCOUNT_NAME);
			String account_surname = account.getAsString(ACCOUNT_SURNAME);
			String account_lastLocation = account.getAsString(ACCOUNT_LASTLOC);
			
			//riferimenti ad oggetti textview che conterranno le informazioni
			ImageView account_avatar =			(ImageView) findViewById(R.id.accountInfo_avatar_imageView);
			TextView account_ID_textView	= 	(TextView) findViewById(R.id.accountInfo_id_textView);
			TextView account_name_textView =	(TextView) findViewById(R.id.accountInfo_name_textView);
			TextView account_surname_textView =	(TextView) findViewById(R.id.accountInfo_surname_textView);
			TextView account_lastLocation_textView=(TextView) findViewById(R.id.accountInfo_lastLocation_textView);
			TextView account_email_textView =	(TextView) findViewById(R.id.accountInfo_email_textView);
			TextView account_username_textView =(TextView) findViewById(R.id.accountInfo_username_textView);
			TextView account_creationDate_textView=(TextView) findViewById(R.id.accountInfo_creationDate_textView);
			
			
			if(image_avatar!=null)
				 account_avatar.setImageDrawable(Drawable.createFromStream(new ByteArrayInputStream(image_avatar), "avatar"));
			
			if(account_name!=null)
				account_name_textView.setText(account_name);
			
			if(account_email!=null)
				account_email_textView.setText(account_email);
				
			if(account_surname!=null)
				account_surname_textView.setText(account_surname);
			if(account_username!=null)
				account_username_textView.setText(account_username);
			if(account_lastLocation!=null)
				account_lastLocation_textView.setText(account_lastLocation);
			if(account_creationDate!=null)
				account_creationDate_textView.setText(account_creationDate);
			if(account_ID!=null)
				account_ID_textView.setText(account_ID);
									
			
		}
		else{
			Toast.makeText(this, "Error: no account data found", Toast.LENGTH_LONG).show();
			//back to login
			//startActivity(new Intent(this,Login_Activity.class));
		}
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_accountinfo_, menu);
		return true;
	}

}
